package chapter2.observerMode.observer.impl;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Observable;
import java.util.Observer;

public class OnlyTimePlate implements Observer {
    public OnlyTimePlate(Observable observable){
        observable.addObserver(this);
    }

    @Override
    public void update(Observable o, Object arg) {
        if(arg != null && arg instanceof LocalDateTime){
            display((LocalDateTime)arg);
        }
    }

    public void display(LocalDateTime dateTime){
        System.out.printf("现在是北京时间%s\n", dateTime.format(DateTimeFormatter.ISO_TIME));
    }
}
